from abc import ABC, abstractmethod

# 产品
class Product:
    def __init__(self):
        self.parts = []

    def add(self, part):
        self.parts.append(part)

    def show(self):
        print("\n--- Show ---")
        for part in self.parts:
            print(part)

# 抽象建造者
class Builder(ABC):
    @abstractmethod
    def build_part_a(self):
        pass

    @abstractmethod
    def build_part_b(self):
        pass

    @abstractmethod
    def build_part_c(self):
        pass

    @abstractmethod
    def get_result(self) -> Product:
        pass

# 具体建造者
class ConcreteBuilder(Builder):
    def __init__(self):
        self.product = Product()

    def build_part_a(self):
        self.product.add("PartA")

    def build_part_b(self):
        self.product.add("PartB")

    def build_part_c(self):
        self.product.add("PartC")

    def get_result(self) -> Product:
        return self.product

# 指挥者
class Director:
    def __init__(self, builder: Builder):
        self.builder = builder

    def construct(self):
        self.builder.build_part_a()
        self.builder.build_part_b()
        self.builder.build_part_c()
        return self.builder.get_result()

# 客户端代码
if __name__ == "__main__":
    builder = ConcreteBuilder()
    director = Director(builder)

    print("Client: I'm not aware of the creator, but I can work with the product.")
    product = director.construct()
    product.show()


#     代码实现:Client: I'm not aware of the creator, but I can work with the product.
#
# --- Show ---
# PartA
# PartB
# PartC
